python class get attribute by name

55

python class get attribute by name -

>>> class c:
        pass
o = c()
>>> setattr(o, "foo", "bar")
>>> o.foo
'bar'
>>> getattr(o, "foo")
'bar'

Comments

Submit
0 Comments